home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_058 / wbdump / wbdump.c < prev   
C/C++ Source or Header  |  1992-05-06  |  5KB  |  148 lines

  1. /* WBdump.c - fast EX-800 workbench print dump (c) 1987 DJH
  2.  
  3.     It seemed to me that the Amiga JX-80 driver was vastly inefficient
  4.   for full screen dumps; so I wrote this routine to see how fast I could
  5.   press my Epson EX-800. The EX is JX-80 compatable, although MUCH faster.
  6.   This program will create beautiful Workbench snapshots in 29-53 seconds,
  7.   depending on mode. Contrast this with the 3 min 48 sec as produced by
  8.   DumpRPort. In all fairness however, this routine does not attempt to
  9.   remain faithful to the actual onscreen colors; no dithering, etc.
  10.  
  11.   PRINT OPTIMIZATIONS OVER PRT:
  12.     1) Bidirectional graphic printing supported. Despite what the RKM
  13.            sez, it sped up several modes by around 20%; and the graphics
  14.            are blur-free.
  15.         2) Blank colors don't even THINK about getting printed!
  16.         3) Built-in Epson aspect ratios preserved; sharper & faster print
  17.         4) Background color is assumed white, saving ribbon
  18.         5) Remaining colors are ribbon primaries, avoiding color mixing
  19.  
  20.     A substantial amount of time in this pgm is spent just performing
  21.   ReadPixel()'s. Feel free to optimize this; Compare running this program
  22.   normally, vs. saving the processed output to RAM: and printing the result
  23.   via "copy ram:fspec to PAR:". I got THIRTEEN SECOND pictures this way!
  24.  
  25.     This program is just a (useful) kernel; it should still work with
  26.   the Epson JX-80, although I have no way of actually testing this. Have Fun!
  27.  
  28.   BENCHMARKS : (printer=Epson EX-800, test screen : NewZAP 3.0 (4-color WB)
  29.  
  30.   MODE : 0 Single-Density        : 32 sec
  31.        1 Double-Density        : 39 sec (good mode)
  32.      2 High-Speed Double-Density    : 29 sec
  33.      3 Quad-Density            : 29 sec
  34.      4 CRT-I            : 53 sec
  35.      5 Plotter            : 39 sec
  36.      6 CRT-II            : 48 sec (default mode)
  37.      7 Double-Density Plotter    : 44 sec (slightly better than 1)
  38.  
  39.   USAGE : WBDump [filespec,mode,overstrike]
  40.   DEFAULTS : WBDump par:,DEFAULT_MODE,1
  41. */
  42.  
  43.  
  44. #define DEFAULT_MODE 0x06 /* CRT-II is a nice size */
  45.  
  46. void *GfxBase,*IntuitionBase;
  47.  
  48. color_table[] = { 0x00,0x00,0x02,0x01 }; /* stick to YMCB for speed */
  49.  
  50. UBYTE init_sequence[] = { 0x1b,0x40,0x1b,0x33,0x18,0x1b,0x55,0x30 },
  51.       set_grafix[] = { 0x1b,0x2a,DEFAULT_MODE,0x80,0x2 },
  52.       set_color[] = { 0x1b,0x72,0x00 },
  53.       cr[] = { 0x0d },
  54.       lf[] = { 0x0a };
  55.  
  56. struct FileHandle *fp;
  57.  
  58. main(argc,argv)
  59. int argc;
  60. char *argv[];
  61. {
  62.   struct Window *window;
  63.   struct NewWindow nw;
  64.   struct Screen *wbscreen;
  65.  
  66.   if (argc>=2)
  67.    if (*argv[1]=='?') {
  68.      puts("WBDump Usage : WBDump [filename,mode,overstrike]");
  69.      exit(0);
  70.    }
  71.    else puts("WBDump : (c) 1987 John Hodgson");
  72.  
  73.   GfxBase=OpenLibrary("graphics.library",0);
  74.   IntuitionBase=OpenLibrary("intuition.library",0);
  75.  
  76.   setmem(&nw,sizeof(nw),0);
  77.  
  78.   nw.Height=20; nw.Width=20; /* goal is inconspicuous */
  79.   nw.Flags=SIMPLE_REFRESH|BORDERLESS|BACKDROP;
  80.   nw.Type=WBENCHSCREEN; /* 'cuz we want the WB Screen ptr */
  81.  
  82.   /* open window just long enough to find WorkBench */
  83.  
  84.   if (!(window=OpenWindow(&nw))) exit(0);
  85.   wbscreen=window->WScreen; CloseWindow(window);
  86.   
  87.   if (argc>=2) fp=Open(argv[1],MODE_NEWFILE);
  88.     else fp=Open("par:",MODE_NEWFILE);
  89.   if (argc>=3) set_grafix[2]=argv[2][0]-'0';
  90.  
  91.   if (!fp) goto cleanup;
  92.  
  93.   Write(fp,&init_sequence[0],sizeof(init_sequence));
  94.   Pack_Bytes(wbscreen,(argc==4) ? argv[3][0]-'0' : 1);
  95.  
  96.   Close(fp);
  97.  
  98. cleanup:
  99.   CloseLibrary(IntuitionBase);
  100.   CloseLibrary(GfxBase);
  101. }
  102.  
  103. Pack_Bytes(screen,overstrike)
  104. struct Screen *screen;
  105. short overstrike;
  106. {
  107.   short cols=screen->BitMap.BytesPerRow*8,
  108.         rows=screen->BitMap.Rows,
  109.         colorcnt=1<<screen->BitMap.Depth,
  110.         i,k,x,y,bit,pixel,hits;
  111.  
  112.   UBYTE *rowcolor[32];
  113.  
  114.   setmem(&rowcolor[0],sizeof(rowcolor),0);
  115.  
  116.   for (i=1;i<colorcnt;i++) /* no need to allocate BG color */
  117.     if (!(rowcolor[i]=AllocMem(cols,MEMF_PUBLIC))) goto cleanup;
  118.   
  119.   for (y=0;y<rows;y+=8) {
  120.  
  121.     for (i=1;i<colorcnt;i++) setmem(rowcolor[i],cols,0);
  122.  
  123.     for (x=hits=0;x<cols;x++)
  124.       for (i=0,bit=7;i<8;i++,bit--) {
  125.         pixel=ReadPixel(&screen->RastPort,x,y+i);
  126.         if (pixel) { /* BG color takes care of itself */
  127.           rowcolor[pixel][x]|=1<<bit;
  128.           hits|=1<<pixel;
  129.         }
  130.       }
  131.  
  132.     for (i=1;i<colorcnt;i++) /* skip backgrnd color; white paper's fine */
  133.       if (hits & 1<<i) {
  134.         set_color[2]=color_table[i];
  135.         for (k=0;k<overstrike;k++) { /* optional overstrike for BOLD colors */
  136.           Write(fp,&set_color[0],sizeof(set_color));
  137.           Write(fp,&set_grafix[0],sizeof(set_grafix));
  138.           Write(fp,rowcolor[i],cols);
  139.           Write(fp,&cr[0],sizeof(cr));
  140.         }
  141.       }
  142.     Write(fp,&lf[0],sizeof(lf));
  143.   }
  144.  
  145. cleanup:
  146.   for (i=1;i<colorcnt;i++) if (rowcolor[i]) FreeMem(rowcolor[i],cols);
  147. }
  148.